﻿using System;
using System.Web.UI;

namespace AjaxDataControls
{   
    /// <summary>
    /// The CustomScriptControlDescriptor object has the script to the client class
    /// and a line to set the variable named based on ClientID with the DOM instance element.
    /// </summary>
    public class CustomScriptControlDescriptor : ScriptControlDescriptor
    {
        protected string id;

        /// <summary>
        /// Gets or sets the name of the variable used to set the DOM element on client.
        /// </summary>
        /// <value>Used to be the same of the ClientID</value>
        public string ServerID
        {
            get { return this.id; }
            set { this.id = value; }
        }

        public CustomScriptControlDescriptor(string id, string type, string elementID) 
            : base(type, elementID)
        {
            this.ServerID = id;
        }

        protected override string GetScript()
        {
            return string.Format("{0}\n{1} = $find('{2}');", 
                                base.GetScript(), this.ServerID, this.ClientID);
        }
    }
}
